package com.google.gwt.mobile.widgets.event;

import com.google.gwt.user.client.Event;

/**
 * The Class SwipeEvent.
 */
public class SwipeEvent extends AbstractTouchEvent<SwipeEventHandler> {

  public static final Type<SwipeEventHandler> TYPE = new Type<SwipeEventHandler>();

  /**
   * The Enum Direction.
   */
  public enum Direction {
    UP, DOWN, RIGHT, LEFT
  };

  private final double _speed;

  private final Direction _direction;

  /**
   * Instantiates a new swipe event.
   * 
   * @param nativeEvent the native event
   * @param type the type
   * @param speed the speed
   */
  public SwipeEvent(final Event nativeEvent, final Direction type, final double speed) {
    super(nativeEvent);

    _direction = type;
    _speed = speed;
  }

  /* (non-Javadoc)
   * @see com.google.gwt.event.shared.GwtEvent#getAssociatedType()
   */
  @Override
  public Type<SwipeEventHandler> getAssociatedType() {
    return TYPE;
  }

  /* (non-Javadoc)
   * @see com.google.gwt.event.shared.GwtEvent#dispatch(com.google.gwt.event.shared.EventHandler)
   */
  @Override
  public void dispatch(final SwipeEventHandler handler) {
    switch (_direction) {
      case UP:
        handler.onSwipeUp(this);
        break;
      case DOWN:
        handler.onSwipeDown(this);
        break;
      case LEFT:
        handler.onSwipeLeft(this);
        break;
      case RIGHT:
        handler.onSwipeRight(this);
        break;
      default:
        break;
    }
  }

  /**
   * Gets the direction.
   * 
   * @return the direction
   */
  public Direction getDirection() {
    return _direction;
  }

  /**
   * Gets the speed.
   * 
   * @return the speed
   */
  public double getSpeed() {
    return _speed;
  }
}
